<!DOCTYPE html>
<html>

{include file='public/header'}
<style>
    .layui-inline{margin-bottom: 5px;}
</style>
<body>
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-inline">
                <label class="layui-form-label w-auto">负责人：</label>
                <div id="responsibilityPerson"></div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label w-auto">链接id：</label>
                <div class="layui-input-inline">
                    <input type="text" name="link_id" placeholder="请输入链接id" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label w-auto">日期：</label>
                <div class="layui-inline" id="time" style="display: flex;align-items: center;">
                    <div class="layui-input-inline" style="margin-right:10px">
                        <input type="text" class="layui-input" name="start_date" id="start_time" autocomplete="off" placeholder="开始时间">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="end_date" id="end_time" autocomplete="off" placeholder="结束日期">
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label w-auto">投放平台：</label>
                <div id="pMedia" style="width:100%;flex:1"></div>
            </div>
            <input type="hidden" id="month" name="month">
            <div class="layui-inline">
                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
                <button type="button" id="leading-out" class="layui-btn layui-btn-normal">导出</button>
            </div>
        </form>
    </div>
    <table id="byPeopleList" lay-filter="byPeopleList"></table>
    <script>
        let responsibility_person_id = GetQueryString('responsibility_person_id')
        let month = GetQueryString('month') ?? ''
        let start_date = GetQueryString('start_date') ?? ''
        let end_date = GetQueryString('end_date') ?? ''
        let totalObj = {};
        $('#month').val(month)
        let params = {
            responsibility_person_id,
            month,
            start_date,
            end_date,
            source:true
        }
        layui.use(['table',"form", "layer",'laydate'], function () {
            var table = layui.table
                form = layui.form,
                laydate = layui.laydate,
                layer = layui.layer;
            // 日期
            laydate.render({
                elem: '#time',
                range:['#start_time','#end_time'],
                value:[start_date,end_date],
                format: 'yyyy-MM-dd'
            });
            let tableOptions = {
                elem: '#byPeopleList'
                , url: `/cps/launch/getPeopleList` //数据接口
                , id: 'byPeopleList'
                , where:params
                , page:true
                , limit:15
                , totalRow:true
                , cols: [[ //表头
                    { field: 'date', width: 105, title: '日期', align:'center' ,totalRowText: '总合计：'}
                    , { field: 'responsibility_person_name', width: 110, title: '负责人', align:'center'}
                    , { field: 'cost', title: '消耗', align:'center'}
                    , { field: 'link_id', width:80, title: '链接ID', align:'center'}
                    , { field: 'actual_cost', title: '实际消耗', align:'center'}
                    , { field: 'register_user_num', title: '注册用户', align:'center'}
                    , { field: 'activation_user_num', title: '激活用户', align:'center'}
                    , { field: 'current_recharge', title: '充值', align:'center'}
                    , { field: 'total_recharge',  title: '累计充值', align:'center'}
                    , { field: 'current_income', title: '收益', align:'center'}
                    , { field: 'total_income',  title: '累计收益', align:'center'}
                    , { field: 'current_recovery',  title: '返后ROI', align:'center'}
                    
                    
                    , { field: 'total_recovery',  title: '累计ROI', align:'center'}
                    , { field: 'recharge_number', title: '订单数', align:'center'}
                    , { field: 'conversion_number', title: '充值人数', align:'center'}
                    , { field: 'per_capita_contribution', width:110, title: '人均充值', align:'center',width:120}
                ]],
                customTotal:function(where){
                    getTotal('/cps/launch/getPeopleListCount',totalObj,where).then(val=>{
                        totalObj = val
                    })
                },
                done:function(){
                    setPrice(totalObj)
                },
                reset:function(){
                    tableOptions.where = params;
                    selectParams1.selected = [responsibility_person_id]
                    selectN(selectParams1)
                }
            };
            tableList(tableOptions)
            form.on('submit(searchList)', function(data){
                params = data.field;
                if(params.responsibility_person_id == ''){
                    layer.msg('请选择负责人',{icon:5,time:2000}); 
                    return false;
                }
                return false
            });
        });

        $("#leading-out").click(function() {
            var data = $('form').serialize();
            derive('/cps/export/bySearchViewExport',data)
        });
        
        let selectParams1 = {
            url: '/cps/responsibilityPerson/select?type=1',
            elem: '#responsibilityPerson',
            selected: [responsibility_person_id],
            tips: '选择负责人',
            name: 'responsibility_person_id',
            field_id: 'responsibility_person_id',
            field_Name: 'responsibility_person_name',
        }
        selectN(selectParams1)
        let selectMedia = {
            url: '/cps/launch/getLaunchMedia',
            selected: [],
            tips: '选择平台',
            name: 'media_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMedia'
        }
        selectN(selectMedia)
        
        function setPrice(totalObj){
            Object.keys(totalObj).forEach(item=>{
                $(`.layui-table-total td[data-field=${item}] .layui-table-cell`).text(totalObj[item]);
            })
        }
    </script>
</body>

</html>